<template>
  <div id="toolBar">
    <button @click="drawBillboard">绘制点</button>
    <button @click="drawLine">绘制线</button>
    <button @click="drawPolygon">绘制面</button>
    <button @click="clearOne">单个清除</button>
    <button @click="clearAll">全部清除</button>
  </div>
</template>

<script lang="ts">
import { inject, onMounted } from 'vue'
import { Viewer } from 'cesium'
import { DrawPolt } from '@/draw/index'
export default {
  name: 'CesiumContainer',
  setup () {
    const viewer = inject<Viewer>('Viewer')
    if (!viewer) return
    let draw: DrawPolt
    let drawElement: HTMLElement | null = null
    onMounted(() => {
      /* eslint no-new: */
      draw = new DrawPolt({
        viewer
      })
      drawElement = document.querySelector('.cesium-widget, .cesium-widget canvas')
      draw.setCanvas(drawElement)
    })
    const drawBillboard = () => {
      draw.create('drawpoint')
    }
    const drawLine = () => {
      draw.create('drawpolyline')
    }
    const drawPolygon = () => {
      draw.create('drawpolygon')
    }
    const clearOne = () => {
      draw.clearOne()
    }
    const clearAll = () => {
      draw.clearAll()
    }
    return {
      drawBillboard,
      drawLine,
      drawPolygon,
      clearOne,
      clearAll
    }
  }
}
</script>
<style scoped>
#cesiumContainer {
  width: 100%;
  height: 100%;
}
#toolBar {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 2;
  background: white;
  padding: 5px 5px;
}
</style>
